EclipseRCP 체크박스에서 재귀선택 이벤트 (EclipseRCP recursive selection event in checkbox viewer)[checkbox viewer,체크박스,selection event,선택 이벤트,이클립스 RCP,eclipse RCP]

이미지출처 : www.mobilefish.com

EclipseRCP 체크박스에서 재귀선택 이벤트 (EclipseRCP recursive selection event in checkbox viewer)







It’s Tips for CheckboxViewer.



I found bug that throw selection event three times in CheckboxViewer(CheckboxTreeViewer,CheckboxTableViewer).



This bug appear when user click checkbox on selected object.



Then I disable selection as well as “viewer.setSelection(null);";



And I need the checkbox behave likes the radio button.



I implemented it through history clear.





Code:


boolean isHistory;
Object currentObject;
 
public void selectionChanged(SelectionChangedEvent event) {
    if(isHistory) {
      isHistory = false;
      return;
    }
  if (!event.getSelection().isEmpty()) {

      if (event.getSelection() instanceof IStructuredSelection) {

          if(currentObject!= null) {

            if(! currentObject.equals((IStructuredSelection)event.getSelection()).getFirstElement())) {

              isHistory = true;

            viewer.setChecked(currentObject, false);

              viewer.setSelection(new StructuredSelection(currentObject);

              isHistory = false;

              viewer.setSelection(null);

            }

          }

        currentObject = (IStructuredSelection)event.getSelection()).getFirstElement();

            viewer.setChecked(currentObject , !viewer.getChecked(currentObject ));

            viewer.getTable().setSelection(currentObject.index);

          viewer.setSelection(null);

      }

    }

  }